package com.jinmdz.fmis.mapper.mapper.provider;

import com.jinmdz.fmis.mapper.entity.RecGpsInfoEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

/**
 * 接运车辆GPS信息Provider
 *
 * @author generator
 * @date 2020-06-22 14:03
 */
public class RecGpsInfoProvider {

    /**
     * 增加RecGpsInfo
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-06-22 14:03
     */
    public String insertRecGpsInfo(@Param("entity") RecGpsInfoEntity entity) {
        return new SQL() {
            {
                INSERT_INTO(" rec_gps_info ");

                if (entity.getDeleted() != null) {
                    VALUES(" deleted ", " #{entity.deleted,jdbcType=TINYINT} ");
                }

                VALUES(" car_imei ", " #{entity.carImei,jdbcType=VARCHAR} ");
                VALUES(" car_id ", " #{entity.carId,jdbcType=INTEGER} ");
                VALUES(" rec_id ", " #{entity.recId,jdbcType=INTEGER} ");
                VALUES(" device_status_code ", " #{entity.deviceStatusCode,jdbcType=SMALLINT} ");
                VALUES(" gps_time ", " #{entity.gpsTime,jdbcType=TIMESTAMP} ");
                VALUES(" sys_time ", " #{entity.sysTime,jdbcType=TIMESTAMP} ");
                VALUES(" heart_time ", " #{entity.heartTime,jdbcType=TIMESTAMP} ");
                VALUES(" server_time ", " #{entity.serverTime,jdbcType=TIMESTAMP} ");
                VALUES(" lng ", " #{entity.lng,jdbcType=VARCHAR} ");
                VALUES(" lat ", " #{entity.lat,jdbcType=VARCHAR} ");
                VALUES(" course ", " #{entity.course,jdbcType=VARCHAR} ");
                VALUES(" speed ", " #{entity.speed,jdbcType=VARCHAR} ");
                VALUES(" status ", " #{entity.status,jdbcType=VARCHAR} ");
                VALUES(" acc ", " #{entity.acc,jdbcType=VARCHAR} ");
                VALUES(" acc_seconds ", " #{entity.accSeconds,jdbcType=VARCHAR} ");
                VALUES(" funeral_parlour_code ", " #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                VALUES(" create_user_id ", " #{entity.createUserId,jdbcType=INTEGER} ");

                if (entity.getUnmodified() != null) {
                    VALUES(" unmodified ", " #{entity.unmodified,jdbcType=TINYINT} ");
                }

                VALUES(" modified_user_id ", " #{entity.modifiedUserId,jdbcType=INTEGER} ");
                VALUES(" version ", " unix_timestamp(now()) ");
            }
        }.toString();
    }

    /**
     * 修改RecGpsInfo
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-06-22 14:03
     */
    public String updateRecGpsInfo(@Param("entity") RecGpsInfoEntity entity) {
        return new SQL() {
            {
                UPDATE(" rec_gps_info ");

                if (entity.getDeleted() != null) {
                    SET(" deleted = #{entity.deleted,jdbcType=TINYINT} ");
                }

                SET(" car_imei = #{entity.carImei,jdbcType=VARCHAR} ");
                SET(" car_id = #{entity.carId,jdbcType=INTEGER} ");
                SET(" rec_id = #{entity.recId,jdbcType=INTEGER} ");
                SET(" device_status_code = #{entity.deviceStatusCode,jdbcType=SMALLINT} ");
                SET(" gps_time = #{entity.gpsTime,jdbcType=TIMESTAMP} ");
                SET(" sys_time = #{entity.sysTime,jdbcType=TIMESTAMP} ");
                SET(" heart_time = #{entity.heartTime,jdbcType=TIMESTAMP} ");
                SET(" server_time = #{entity.serverTime,jdbcType=TIMESTAMP} ");
                SET(" lng = #{entity.lng,jdbcType=VARCHAR} ");
                SET(" lat = #{entity.lat,jdbcType=VARCHAR} ");
                SET(" course = #{entity.course,jdbcType=VARCHAR} ");
                SET(" speed = #{entity.speed,jdbcType=VARCHAR} ");
                SET(" status = #{entity.status,jdbcType=VARCHAR} ");
                SET(" acc = #{entity.acc,jdbcType=VARCHAR} ");
                SET(" acc_seconds = #{entity.accSeconds,jdbcType=VARCHAR} ");
                SET(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");

                if (entity.getUnmodified() != null) {
                    SET(" unmodified = #{entity.unmodified,jdbcType=TINYINT} ");
                }

                SET(" modified_user_id = #{entity.modifiedUserId,jdbcType=INTEGER} ");
                SET(" version = unix_timestamp(now()) ");
                WHERE(" id = #{entity.id,jdbcType=INTEGER} ");
                WHERE(" unmodified = 0 ");
                WHERE(" version = #{entity.version,jdbcType=INTEGER} ");
            }
        }.toString();
    }

    /**
     * 查询RecGpsInfo列表
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-06-22 14:03
     */
    public String listRecGpsInfo(@Param("entity") RecGpsInfoEntity entity) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" id,deleted,car_imei,car_id,rec_id,device_status_code,gps_time,sys_time,heart_time,server_time,lng,lat,course,speed,status,acc,acc_seconds,funeral_parlour_code,create_user_id,gmt_create,unmodified,modified_user_id,gmt_modified,version ");
                SELECT(builder.toString());
                FROM(" rec_gps_info ");

                if (entity.getCarImei() != null) {
                    WHERE(" car_imei = #{entity.carImei,jdbcType=VARCHAR} ");
                }

                if (entity.getCarId() != null) {
                    WHERE(" car_id = #{entity.carId,jdbcType=INTEGER} ");
                }

                if (entity.getRecId() != null) {
                    WHERE(" rec_id = #{entity.recId,jdbcType=INTEGER} ");
                }

                if (entity.getDeviceStatusCode() != null) {
                    WHERE(" device_status_code = #{entity.deviceStatusCode,jdbcType=SMALLINT} ");
                }

                if (entity.getGpsTime() != null) {
                    WHERE(" gps_time = #{entity.gpsTime,jdbcType=TIMESTAMP} ");
                }

                if (entity.getSysTime() != null) {
                    WHERE(" sys_time = #{entity.sysTime,jdbcType=TIMESTAMP} ");
                }

                if (entity.getHeartTime() != null) {
                    WHERE(" heart_time = #{entity.heartTime,jdbcType=TIMESTAMP} ");
                }

                if (entity.getServerTime() != null) {
                    WHERE(" server_time = #{entity.serverTime,jdbcType=TIMESTAMP} ");
                }

                if (entity.getLng() != null) {
                    WHERE(" lng = #{entity.lng,jdbcType=VARCHAR} ");
                }

                if (entity.getLat() != null) {
                    WHERE(" lat = #{entity.lat,jdbcType=VARCHAR} ");
                }

                if (entity.getCourse() != null) {
                    WHERE(" course = #{entity.course,jdbcType=VARCHAR} ");
                }

                if (entity.getSpeed() != null) {
                    WHERE(" speed = #{entity.speed,jdbcType=VARCHAR} ");
                }

                if (entity.getStatus() != null) {
                    WHERE(" status = #{entity.status,jdbcType=VARCHAR} ");
                }

                if (entity.getAcc() != null) {
                    WHERE(" acc = #{entity.acc,jdbcType=VARCHAR} ");
                }

                if (entity.getAccSeconds() != null) {
                    WHERE(" acc_seconds = #{entity.accSeconds,jdbcType=VARCHAR} ");
                }

                if (entity.getFuneralParlourCode() != null) {
                    WHERE(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                }

            }
        }.toString();
    }
}